package ex2.employee;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CEquipmentInputReader {

	IEquipmentHandler _EquipmentHandler;
	
	
	public CEquipmentInputReader(IEquipmentHandler EquipmentHandler ){
		this._EquipmentHandler = EquipmentHandler;
	}
	
	public void readInformationFromCommandLine(){
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String tEmquipmentRecord = "";
		
		System.out.println("Enter equipment information");
		
		try
		 {
			tEmquipmentRecord= br.readLine();
		 }
		catch(IOException e){
			e.printStackTrace();
		}
		
		
		while(!tEmquipmentRecord.equals("STOP")){
			
			IEquipment tEquipment = null;
			
			try{
				tEquipment = new CEquipment(tEmquipmentRecord);
				this._EquipmentHandler.addEquipment(tEquipment);
			}
			catch (IllegalArgumentException e){
				malformedRecordInput();
			}
			
			try
			 {
				tEmquipmentRecord= br.readLine();
			 }
			catch(IOException e){
				e.printStackTrace();
			}
			
		}
		
	}
	
	private void malformedRecordInput(){
		System.out.println("Malformed record inserted");
	}
	
}
